Skip to content

Fix tile URL prefix for JupyterHub deployments#39

Open
gcaer wants to merge 1 commit into
geojupyter:mainfrom
gcaer:fix/jupyterhub-base-url
Open

Fix tile URL prefix for JupyterHub deployments#39
gcaer wants to merge 1 commit into
geojupyter:mainfrom
gcaer:fix/jupyterhub-base-url

Conversation

@gcaer

@gcaer gcaer commented Jun 3, 2026

Copy link
Copy Markdown

Note: This diagnosis and fix come from Claude Code. It makes sense to me, but I'm not deep enough in the JupyterGIS internals to be 100% confident. Feel free to close this if it's off-base.

Problem

When jupytergis-tiler is used inside JupyterHub, tile layers added via add_tiler_layer() are not rendered on the map.

In JupyterHub, each user's Jupyter server is served under a URL prefix such as /user/username/. The JupyterGISHandler is therefore registered at /user/username/jupytergis_tiler/(.*). However, tile URLs were hardcoded to /jupytergis_tiler/... without this prefix, so browser requests never reached the handler — JupyterHub had no route to forward them to the user's server.

The issue does not occur in standalone JupyterLab, where base_url is /.

Fix

gis_document.py

Read the JUPYTERHUB_SERVICE_PREFIX environment variable (set by JupyterHub for all single-user servers) to prepend the correct base URL when constructing tile URLs:

base_url = os.environ.get("JUPYTERHUB_SERVICE_PREFIX", "/").rstrip("/")
url = f"{base_url}/jupytergis_tiler/{source_id}/tiles/..."

When JUPYTERHUB_SERVICE_PREFIX is not set (standalone JupyterLab), behaviour is unchanged.

handler.py

The proxy handler now forwards the HTTP status code and the Content-Type header from the upstream tile server response.

Without this fix, errors from the tile server were silently swallowed (always returning HTTP 200), and stricter environments such as JupyterHub (which may set X-Content-Type-Options: nosniff) could refuse to render tiles without an explicit Content-Type: image/png.

Testing

  • Tile layers render correctly in a JupyterHub deployment (with JUPYTERHUB_SERVICE_PREFIX set)
  • Tile layers still render correctly in standalone JupyterLab (without the env var)
  • Tile server errors are now surfaced with the correct HTTP status code

@davidbrochart

Copy link
Copy Markdown
Collaborator

Thanks @GwenaelCaer, but I think the work is now happening in https://github.com/geojupyter/jupyter-tiler.
Maybe @martinRenou or @mfisher87 can confirm.

@gcaer

gcaer commented Jun 3, 2026

Copy link
Copy Markdown
Author

Thanks @davidbrochart , I didn't know this repository existed, I'll have a look at it then ;)

@mfisher87

Copy link
Copy Markdown
Member

Maybe @martinRenou or @mfisher87 can confirm.

Correct! jupyter-tiler is intended to be used with any mapping tool, but it's based on jupytergis-tiler. I'm certain it has the same problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants